window.Bundle = {
	pathForResource : function(resource) {
		return window.Bundle.bundlePath + "/" + resource;
	},
	pathForResourceInDirectory : function(directory, resource) {
		return window.Bundle.bundlePath + "/" + directory + "/" + resource;
	},
	bundlePath : "."
};

window.Data = function () {};
window.Data.prototype = {
	length : 0,
	__bin_data : null,
	asString : function () { return this.__bin_data.toString(); },
	isEqualTo : function (other) { return this.__bin_data === other.__bin_data; },
	loadFromData : function (source) { if (source instanceof window.Data) { this.__bin_data = source.__bin_data; this.length = source.length; return true; } else {return false;} },
	loadFromString : function (source) { if (typeof(source) === "string" || source instanceof String) { this.__bin_data = source; this.length = this.__bin_data.length; return true; } else {return false;} },
	loadFromFile : function (fileName) { this.__bin_data = null; this.length = 0; return true; },
	writeToFile : function (fileName) { return true; }
};
window.Defaults = {
	defaults : { },
	get : function (name) { return window.Defaults.defaults[name]; },
	set : function (name, value) { window.Defaults.defaults[name] = value; },
	remove : function (name) { if (name !== null && typeof(name) !== "undefined") { delete window.Defaults.defaults[name]; } },
	getAll : function () { return window.Defaults.defaults; },
	synchronize : function () { return true; }
};

// Jiggy Globals
window.JiggyVersion = "0.21";

window.print = function (s) { if (console.log) { console.log(s); } };
window.log = function (s) { if (console.log) { var dt = new Date().getTime(); console.log(dt + ": " + s); } };
window.debug = function (on) {
	if (!!on) {
		window.onerror = function (e) {
			console.error(e);
			alert(e);
		};
	} else {
		window.onerror = null;
	}
};
window.include = function (script) {
	var serverResponse = null;
	try {
		var xhReq = new XMLHttpRequest();
		xhReq.open("GET", script, false);
		xhReq.send(null);

		if (xhReq.status === 200 || xhReq.status === 0) {
			serverResponse = xhReq.responseText;
		}
	} catch (ex) {
		throw "include() exception: " + script + " not found.";
	}

	if (serverResponse !== null) {
		window.eval(serverResponse);
	}

};

window.killProcessNamed = function(name) { return true; };
window.terminate = function () { throw "Application Terminated"; };
window.openURL = function (url, openAsPanel) { window.open(url); };
window.executeShellCommand = function (command) { return ""; };

window.onLoad = function() {};
window.onload = function() {
	if (typeof(window.onLoad) === "fuction") {
		window.onLoad();
	}
};
window.onUnload = function() {};
window.onunload = function () {
	if (typeof(window.onUnload) === "fuction") {
		window.onUnload();
	}
};
window.onAccelerate = function (x, y, z) {};

window.Plugins = {
	load : function (pluginName) {
		window.include(pluginName);
		return true;
	}
};

window.Timer = function (seconds) {
	seconds = seconds > 0 ? seconds : 1;
	var t = function () {};
	t.prototype = {
		start : function (seconds) {
			this.stop();
			this.seconds = seconds > 0 ? seconds : this.seconds;
			if (typeof(this.onTimer) === "function") {
				var self = this;
				this.interval_handle = setInterval(function () { self.onTimer(); }, this.seconds * 1000);
			}
		},
		stop : function () {
			if (this.interval_handle != null) {
				clearInterval(this.interval_handle);
				this.interval_handle = null;
			}
		},
		seconds: seconds,
		interval_handle: null,
		onTimer: function () {}	
	};
	return new t();
};